/*
 * Copyright (c) 2020 pig4cloud Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.demo.exception;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author bobo
 * @date 😴2018年06月22日16:21:57
 */
@NoArgsConstructor
@Data
public class BizException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    private Integer code = 500;

    private String msg;


    /**
     * 无参构造，默认返回异常
     */
    /*public BizException() {
        super(ErrorCodeEnum.UNSPECIFIED.getMsg());
        this.code = ErrorCodeEnum.UNSPECIFIED.getCode();
        this.msg = ErrorCodeEnum.UNSPECIFIED.getMsg();
    }*/

    /**
     * 根据错误码获取异常信息
     *
     * @param code
     */
    /*public BizException(Integer code) {
        super(ErrorCodeEnum.getByCode(code).getMsg());
        this.code = ErrorCodeEnum.getByCode(code).getCode();
        this.msg = ErrorCodeEnum.getByCode(code).getMsg();
    }*/

    /**
     * 根据枚举返回异常信息
     */
    public BizException(ErrorCode errorEnum) {
		super(errorEnum.getMsg());
		this.code = errorEnum.getCode();
		this.msg = errorEnum.getMsg();
    }

	/**
	 * 返回自定义提示异常信息
	 * @param message
	 */
	public BizException(String message) {
        super(message);
        this.msg = message;
        this.code = code;
    }

    public BizException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    public BizException(Throwable cause) {
        super(cause);
    }

    public BizException(String message, Throwable cause) {
        super(message, cause);
    }

    public BizException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }

}
